package com.servlet.users;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UsersDAO;

public class DelectUsersByNameServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String userName = request.getParameter("user_name");
		UsersDAO usersDAO = new UsersDAO();//得到DAO对象

		String msg = "失败";
		if (usersDAO.delectByName(userName)) {
			msg = "成功";
		}
		// 提示消息
		request.setAttribute("msg", "删除用户" + msg);
		// 返回路径
		request.setAttribute("returnPath", "/FindAllBookInfoServlet");
		request.getRequestDispatcher("/background/message.jsp").forward(
				request, response);//跳转到该路径
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String userName = request.getParameter("user_name");
		UsersDAO usersDAO = new UsersDAO();//得到DAO对象

		String msg = "失败";
		if (usersDAO.delectByName(userName)) {
			msg = "成功";
		}
		// 提示消息
		request.setAttribute("msg", "删除用户" + msg);
		// 返回路径
		request.setAttribute("returnPath", "/FindAllBookInfoServlet");
		request.getRequestDispatcher("/background/message.jsp").forward(
				request, response);//跳转到该路径
	}

}
